<?php
/* @var $this PackageController */

$this->breadcrumbs=array(
	'Package',
);
//行业
$category = Category::model()->findByPk($product->zca_id);
//父级行业，用于导航栏
$category_parent = Category::model()->findByPk($category->zca_parentid);
//顶级行业,用于导航
$category_top = Category::model()->findByPk($category->zca_topid);

//行业顶级ID
$topid = ($category->zca_parentid>0)?(($category->zca_topid>0)?$category->zca_topid:$category->zca_parentid):$category->zca_id;
//分类二级ID
$parentid = ($category->zca_parentid>0)?(($category->zca_topid>0)?$category->zca_parentid:$category->zca_id):0;

//分类缓存
$categoryCache = Category::model()->GetCatCache();

//热销产品推荐
$criteria=new CDbCriteria;
$criteria->compare('zp_status',2);
$criteria->compare('zp_state',2);
$criteria->compare('zca_id',$product->zca_id);
$criteria->limit = 8;
$criteria->order = 'zp_sale_num DESC';
$hotRecommend = Product::model()->findAll($criteria);      

?>
<!--正文start-->
<div class="w_960 o_a">
	<div class="col_sub w_190 f_l">
        <!--宝贝分类start-->
        <div class="pro_classify">
            <div class="hd bg"><h2 class="fs_14"><a class="c_white" href="javascript:">所有宝贝分类</a></h2></div>
            <div class="bd">
                <ul id="proSort">
                    <?php foreach($categoryCache as $key=>$val){?>    
                        <?php if($val['zca_visible']==1){?>                
                        <li class="item <?php if($topid == $val['zca_id']){?> open<?php }?>">
                            <h3 class="c_green3 bg_x click"><?php echo $val['zca_title'] ?></h3>
                            <div class="list">
                                <ul class="li">
                                <?php if(isset($val['subcat'])){ foreach( $val['subcat'] as $key2=>$val2 ){?>
                                    <?php if($val2['zca_visible']==1){?>  
                                        <li class="<?php if($parentid == $val2['zca_id']){?> open<?php }?>">
                                            <p class="h"><span class="ico ico_fold click2"></span><?php echo CHtml::link($val2['zca_title'], array('/home/product/list', 'id' => $val2['zca_id']), array('title' => $val2['zca_title'],'class' => 'c_666 fw_b'))?><span class="c_999 d_n">（<?php echo $val2['pro_count'] ?>）</span></p>
                                            <ul class="sub line_20">
                                              <?php if(isset($val2['subcat'])){  foreach( (array)$val2['subcat'] as $key3=>$val3 ){?>
                                                  <?php if($val3['zca_visible']==1){?>  
                                                    <li><?php echo CHtml::link($val3['zca_title'], array('/home/product/list', 'id' => $val3['zca_id']), array('title' => $val3['zca_title'],'class' => 'c_999'))?><span class="c_999 d_n">（<?php echo $val3['pro_count'] ?>）</span></li>
                                                  <?php }?>
                                              <?php }}?>
                                            </ul>
                                        </li>
                                    <?php }?>
                                <?php }}?>
                                </ul>
                            </div>
                        </li>     
                        <?php }?>               
                    <?php }?>
                </ul>
            </div>
        </div>
        <!--宝贝分类end-->
        <!--同类产品推荐 start-->
        <div class="like_pro c_f mt10 bg_fff list_hover">
        	<div class="hd bg_x"><span class="fs_14 fw_b">同类产品推荐</span></div>
            <div class="bd">
            	<ul>
                    <?php
					$criteria=new CDbCriteria;
					$criteria->compare('zp_status',2);
					$criteria->compare('zp_state',2);
					$criteria->compare('zca_id',$product->zca_id);
					$criteria->addCondition("zp_id != {$product->zp_id}");
					$criteria->limit = 5;
                    $items = Product::model()->findAll($criteria);
                    if ($items) {                        
                        foreach ($items as $i) {
                            ?>
                            <li class="item">
                                <div class="c_img c_img160"><?php echo CHtml::link( Tool::thumb( $i->zp_pic,160,160,$i->zp_name ),array('/home/product/detail/', 'id'=>$i->zp_id ),array('target'=>'_blank','title'=>$i->zp_name) ) ?></div>
                                <p class="price ff_yh"><strong class="c_orange fs_15">&yen;<?php echo $i->zp_price ?></strong></p>
                                <p class="title title_pro c_666"><?php echo $i->getTitle() ?></p>
                            </li>                                            
                            <?php
                        }
                        
                    } else {
                        ?>
                        <p style="text-align:center">没有找到商品!</p>
                    <?php } ?>                	
                </ul>
            </div>
        </div>
        <!--同类产品推荐 end-->
        <!--浏览记录 start-->
        <div class="pub_a view_history c_f mt10 bg_fff">
        	<div class="hd bg_x"><a class="f_r c_06c" href="javascript:" title="">清除</a><span class="fs_14 fw_b">浏览记录</span></div>
            <div class="bd">
            	<ul>
                    <?php 
                        //取浏览记录
                        $proids = MemHistory::model()->readBrowsingHistory();
                        if (!empty($proids)) {
	                        $criteria=new CDbCriteria;
	                        $criteria->addInCondition('zp_id',$proids);
	                        $items = Product::model()->findAll($criteria);                      
	                        foreach ($items as $i) {
                    ?>
                        <li class="c_f">
	                        <div class="c_img c_img50 f_l"><?php echo CHtml::link( Tool::thumb( $i->zp_pic,50,50,$i->zp_name ),array('/home/product/detail/', 'id'=>$i->zp_id ),array('target'=>'_blank','title'=>$i->zp_name) ) ?></div>
	                        <p class="title title_pro1"><?php echo $i->getTitle() ?></p>
	                        <p class="price ff_yh"><strong class="c_orange fs_14">&yen;<?php echo $i->zp_price ?></strong></p>
                    	</li>
                    <?php
                        }
                        
                    } else {
                        ?>
                        <p style="text-align:center">没有找到浏览记录!</p>
                    <?php } ?>  
                </ul>
            </div>
        </div>
        <!--浏览记录 end-->
        <!--左边栏底部广告 L1 94 start-->
        <?php $adzone = Adzone::model()->getData(94);
        foreach( (array)$adzone['ads'] as $key=>$value){?>
        <div class="adv mt10">
            <?php echo CHtml::link(CHtml::image($value['zds_file_url'],!empty($value['zdz_desc'])?$value['zdz_desc']:'A1',array('height'=>$adzone['zdz_height'],'width'=>$adzone['zdz_width']),$value['zds_url'],array('target'=>'_blank')))?>
        </div>
        <?php }?>        
        <!--左边栏底部广告 L1 94 end-->
    </div> 
    <div class="col_main w_760 f_r">
    	<div class="detail_info packages_info">
           <?php echo CHtml::beginForm(array('/cart/addToCart'), 'POST', array('id' => 'orderForm')) ?>
           
        	<div class="summary c_f">
				<div class="img" id="photoAlbum">
					<div id="superAlbum">
						<span class="img_mask" id="img_mask"></span>
                        <div class="c_img big_img"><a href="javascript:"><?php echo Tool::thumb($product->zp_pic,240,240,$product->zp_name,array('id'=>'bigPIC','data-superbig'=>$product->zp_pic))?></a></div>
					</div>
					<ul class="s_img_list album_list c_f" id="album_list">
					<?php foreach($product->proimg as $val){?>
						<li class="item <?php if($val->zpg_url==$product->zp_pic) echo "select"?>">
						<?php echo CHtml::link(Tool::thumb($val->zpg_url,40,40),array($val->zpg_url),array('data-superbig'=>$val->zpg_url))?>
						</li>
					<?php }?>
					</ul>
				</div>
				<div class="info">
                	<h2 class="c_666 fs_14 line_24">套餐名称<?php echo CHtml::encode($model->zpp_title)?></h2>
                    <div class="price_box c_f">
                    	<div class="flag bg">
                        	<p class="ff_yh">立省</p>
                            <p class="fw_b"><?php echo $model->costPrice - $model->zpp_price?></p>
                        </div>
                        <ul>
                        	<li class="item c_f"><span class="a">市场价：</span><span class="b"><?php echo $model->costPrice ?>元</span></li>
							<li class="item c_f"><span class="a">促销价：</span><span class="b"><em class="price"><?php echo $model->zpp_price ?></em> 元</span></li>
                        </ul>
                    </div>
					<ul>
						<li class="item c_f"><span class="a">配送：</span>
                            <?php if($model->zpp_exp_status==1){?>
                                <span class="b">卖家包邮</span>
                                <?php }else{?>
                                <span class="b">送至</span>
                                <span class="c po">
                                    <input class="select_city ico" id="change_city" type="button" value="深圳" />
                                    <div class="change_city_inner" id="change_city_inner" style="display:none;">
                                        <ul class="zxCity c_f" id="C_zxCity">
                                            
                                        </ul>
                                        <ul class="province c_f" id="C_area">
                                            
                                        </ul>
                                        <ul class="city c_f" id="C_city" style="display:none;">
                                            
                                        </ul>
                                        <a href="javascript:" class="close">关闭</a>
                                    </div>
                                </span>
                                <span class="d"><em>快递：10元</em><em>EMS：20元</em></span>
                                <?php }?>                           
						</li>
					</ul>
				</div> 
			</div>
            <div class="property_box">
            	<h3>本优惠套餐包含以下商品：</h3>
                <div class="property c_f">
                <?php foreach($model->products as $data){?>
                	<div class="box">
                    	<div class="pro c_f">
                        	<div class="c_img c_img80">
                        		<?php echo CHtml::link(Tool::thumb($data->zp_pic,80,80,$data->zp_name,array('style'=>'display: inline-block; width: 80px; height: 80px;')),array('/home/product/detail','id'=>$data->zp_id),array('target'=>'_blank','title'=>$data->zp_name))?>
                        	</div>
                            <div class="info">
                            	<p>
                            	<?php echo CHtml::link(mb_substr($data->zp_name,0,20,'utf8'),array('/home/product/detail','id'=>$data->zp_id),array('target'=>'_blank','title'=>$data->zp_name,'class'=>'c_06c'))?>
                            	</p>
                                <p class="c_666 mt10"><span class="mr10">&yen; <strong class="ff_yh fs_18 c_red2"><?php echo $data->zp_price?></strong>元</span></p>
                            </div>
                        </div>
                        <div class="shopping">
                            <input type="hidden" name="proinfo[product][<?php echo $data->zp_id?>][id]" value="<?php echo $data->zp_id?>" />
                            <input type="hidden" name="proinfo[product][<?php echo $data->zp_id?>][packageid]" value="<?php echo $model->zpp_id?>" />
                            <input type="hidden" name="proinfo[product][<?php echo $data->zp_id?>][name]" value="<?php echo $data->zp_name?>" />
                            <input type="hidden" name="proinfo[product][<?php echo $data->zp_id?>][title]" value="<?php echo $data->zp_name?>" />                            
                            <input type="hidden" name="proinfo[product][<?php echo $data->zp_id?>][saleprice]" value="<?php echo $data->zp_price?>" />                           
                            <?php echo CHtml::hiddenField('proinfo[product]['.$data->zp_id.'][zel_id]', $model->zel_id) ?> 
                            <?php 
	                            $stas = null;                                
	                            foreach($data->standard as $sta){                                    
									//判断是否支持图片
									$sta->zpa_pic = trim($sta->zpa_pic);
									if($sta->zps_photo==2&&!empty($sta->zpa_pic)){
										$stas[$sta->za_id][] = CHtml::link(Tool::thumb($sta->zpa_pic,32,32,$sta->zpa_val),'javascript:');
	                            	}else{
	                            		$stas[$sta->za_id][$sta->zpa_id] = CHtml::link($sta->zpa_val,'javascript:',array('onclick'=>"sele_spec(this,$sta->za_id$sta->zp_id,$sta->zpa_id,'$sta->zpa_val')"));
	                            	}                                    
	                            }
                            ?>                          
                            <?php foreach($stas as $key=>$sta){?>
                             <input type="hidden" name="proinfo[product][<?php echo $data->zp_id?>][spe][]" id="sel_color_ipt_<?php echo $key?><?php echo $data->zp_id?>"  />
                            <div class="lin c_f">
                                <p class="left"><?php echo CHtml::encode(Attribute::model()->findByPk($key)->za_title)?>：</p>
                                <ul class="s_txt_list s_txt_list_small" id="sel_color_<?php echo $key?><?php echo $data->zp_id?>">    
                                	<?php foreach($sta as $key2=>$val2){ ?>                                
                                    <li data-value="0" class="item" id="show_id_<?php echo $key2?>"><?php echo $val2 ?></li>
                                    <?php } ?>
                                </ul>
                            </div>
                            <?php }?>
                        </div>
                    </div>
                    <?php }?>
                </div>
                <div class="buy_box">
                	<div class="num">我要买：<input class="t_ipt" type="text" name="proinfo[qty]" value="1" size="6" />套</div>
                    <div class="buy"><a class="btn" href="javascript:" title="" onclick="$('#orderForm').submit()"></a></div>
                </div>
            </div>
            <?php echo CHtml::hiddenField('proinfo[exp_status]', $model->zpp_exp_status) ?>             
            <?php echo CHtml::hiddenField('proinfo[saleprice]', $model->costPrice) ?>             
            <?php echo CHtml::hiddenField('proinfo[price]', $model->zpp_price) ?>
            <?php echo CHtml::hiddenField('proinfo[packageid]', $model->zpp_id) ?>
           <?php echo CHtml::endForm(); ?>
        </div>
        <div class="hr_20"></div>
        <div class="pro_detail">
            <!--套餐详情 start-->
            <div class="tab_cont2 mt10">
                <div class="detail mt10">
                	<div class="pub_hd hd">套餐详情</div>
                    <div class="bd">
                    	<?php echo Yii::app()->format->formatHtml($model->zpp_content)?>
                    </div>
                </div>
            </div>
            <!--套餐详情 end-->
        </div>
        <div class="hr_15"></div>
        <!--热销推荐 start-->
         <div class="pro_list list_hover">
            <div class="pub_hd">热销推荐</div>
            <div class="bd pro_list">
                <ul class="list c_f">
                <?php foreach($hotRecommend as $key=>$data){?>
                    <li class="item <?php if (($key+1)%4==0){echo "no_mr"; }?>">
                    	<div class="c_img c_img160"><a href="javascript:" title="">
                    		<?php echo CHtml::link(Tool::thumb($data->zp_pic,160,160,$data->zp_name),array('/home/product/detail','id'=>$data->zp_id),array('target'=>'_blank'))?>
                    	</div>
                        <p class="price ff_yh">
                        	<del class="c_999 f_r d_n">&yen;58.00</del>
                        	<strong class="fs_15 c_orange">&yen;<?php echo $data->zp_price?></strong>
                        </p>
                        <p class="title c_666">
                        	<?php echo CHtml::link(mb_substr($data->zp_name,0,20,'utf8'),array('/home/product/detail','id'=>$data->zp_id),array('target'=>'_blank'))?>
                        </p>
                        <p class="buy">
                        	<?php echo CHtml::link('点击购买',array('/home/product/detail','id'=>$data->zp_id),array('target'=>'_blank','class'=>'btn btn_buy'))?>
                        </p>
                    </li>
                <?php }?>
                </ul>
            </div>
        </div>  
        <!--热销推荐 end--> 
    </div>
</div>
<div class="hr_30"></div>
<!--正文end-->
<div class="po_bigView" id="po_bigView"><img src="" class="superPIC" id="superPIC" alt="" /></div>

<script type="text/javascript">
$(function(){
	new photoAlbum($('#photoAlbum'));/*相册*/
	new superIMG2($('#superAlbum'));/*摸过去放大*/	
	$('.packages_info .big_img img').LoadImage(true,240,240);
	//$('#change_city').changeCity();/*选择城市*/
});
//规格的选择
function sele_spec(obj,id,spid,va,type)
{
    
    var ids = '<?php echo isset($speids)?$speids:""?>';  
    var aa = $('#sel_color_ipt_'+id).val();
    var bigPIC = $('#bigPIC');
    var superPIC = $('#superPIC');
    var imgSRC='',superimgSRC='';
    if(aa==va)
    {
        $('#show_id_'+spid).removeClass("select");
        $('#sel_color_ipt_'+id).val('');
    }
    else
    {
        if(aa!=''){$('#sel_color_'+id).find('.item').removeClass("select");}
        $('#sel_color_ipt_'+id).val(va);
        $('#show_id_'+spid).addClass("select");                
        if(type==2)
        {
            var a = $(this).find('a')
            imgSRC = a.attr('href');
            superimgSRC = a.attr('data-superbig')
            bigPIC.attr('src',imgSRC);
            //超级大图
            superPIC.attr('src',superimgSRC);
        }else{
            
        }
    }  
}
</script>